package com.classroommanagesystem.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author victory
 * @date 2025/10/24 17:46
 */


@AllArgsConstructor
@NoArgsConstructor
@Data
public class Result<T> {
    /**
     * 状态码
     */
    private Integer code;
    /**
     * 提示信息，如果有错误时，前端可以获取该字段进行提示
     */
    private String msg;
    /**
     * 查询到的结果数据，
     */
    private T data;

    public static <T> Result<T> success() {
        return new Result<>(1, "操作成功", null);
    }

    public static <T> Result<T> success(T object) {
        return new Result<>(1, "操作成功", object);
    }

    public static <T> Result<T> success(String message, T object) {
        return new Result<>(1, message, object);
    }

    public static <T> Result<T> error() {
        return new Result<>(0, "操作失败", null);
    }

    public static <T> Result<T> error(String message, T object) {
        return new Result<>(0, message, object);
    }


    public static <T> Result<T> error(String message) {
        return new Result<>(0, message, null);
    }
}
